package org.xtframe.service.impl;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import org.xtframe.entity.UserData;
import org.xtframe.service.AjaxDataHandler;
import org.xtframe.util.CommonUtil;
import org.xtframe.util.ContextUtil;

@Service
@Scope("prototype")
public class UserInfoDataHandler implements AjaxDataHandler {

	private final Log logger = LogFactory.getLog(getClass());

	public Map<String, Object> execute(String strData) {
		Map<String, Object> map = new HashMap<String, Object>();
		
		try {
			UserData userData = ContextUtil.getCurrentUserData();
			if(userData == null){
				map.put(STATUS, false);
				map.put(LOGIN, true);
			}else{
				map.put(STATUS, true);
				map.put("userid", userData.getUser().getUserId());
				map.put("username", userData.getUser().getUserName());
				map.put("organid", userData.getUser().getOrganId());
				map.put("organname", userData.getOrgan().getOrganName());
				map.put("jobid", userData.getUser().getJobId());
				map.put("orderno", userData.getUser().getOrderNo());
				map.put("role", userData.getRoleList());
				map.put("create_time", userData.getCreateTime());
				map.put("current_time", System.currentTimeMillis());
				map.put("current_date", CommonUtil.getCurrentTime());
			}
		} catch (Exception e) {
			logger.error(e.toString());
			map.clear();
			map.put(STATUS, false);
		}
		
		return map;
	}

}
